package com.esm.sm800.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

import com.esm.sm800.R;
import com.esm.sm800.database.dbmodel.SystemAllInfo;
import com.esm.sm800.database.manager.SystemCenter;

import zuo.biao.library.base.BaseActivity;

//断针设置
public class DzszActivity extends BaseActivity implements View.OnClickListener {

    private final String TAG = "DzszActivity";

    private EditText et_dzzd;
    private EditText et_dzzc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_dzsz);

        et_dzzd = (EditText) findViewById(R.id.et_dzzd);
        et_dzzc = (EditText) findViewById(R.id.et_dzzc);

        findViewById(R.id.tv_back).setOnClickListener(this);

        SystemAllInfo dzzd = SystemCenter.getInstance().getSysInfo("dzzd");
        if (dzzd != null) {
            et_dzzd.setText(dzzd.getContent());
        } else {
            et_dzzd.setText("80");
        }
        SystemAllInfo dzzc = SystemCenter.getInstance().getSysInfo("dzzc");
        if (dzzc != null) {
            et_dzzc.setText(dzzc.getContent());
        } else {
            et_dzzc.setText("120");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    public static final int REFRESH_UI = 1101;
    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == REFRESH_UI) {

            }
        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.tv_back:
                onSave();
                break;
        }
    }

    private void onSave() {
        String dzzd = et_dzzd.getText().toString();
        String dzzc = et_dzzc.getText().toString();

        try {
            int num1 = Integer.parseInt(dzzd);
            int num2 = Integer.parseInt(dzzc);
        } catch (Exception e) {
            showShortToast(getString(R.string.cwdsz));
            return;
        }

        SystemCenter.getInstance().saveSysInfo(new SystemAllInfo(null, "dzzd", dzzd));
        SystemCenter.getInstance().saveSysInfo(new SystemAllInfo(null, "dzzc", dzzc));

        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
    }


    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }
}
